<template>
  <div class="Admin" style="background-color: white">
    <el-container>
      <el-header>
        <el-row>
          <el-col :span="2" style="display: flex;">
            <h1 style="height: 60px;line-height: 60px;padding-left: 20px;">后台管理</h1>
          </el-col>
          <el-col :span="2" style="display: flex;float: right">
            <el-button style="margin: 15px 0" @click="quit">退出登录</el-button>
          </el-col>
          <el-col :span="2" style="display: flex;float: right">
            <el-button style="margin: 15px 0" @click="toTask">返回前台</el-button>
          </el-col>
        </el-row>
      </el-header>
    </el-container>
    <el-container>
      <el-aside>
        <el-menu :collapse="isCollapse" class="admin-menu" default-active="dash" router>
          <el-menu-item index="/admin/dash">
            <i class="el-icon-monitor"></i>
            <span slot="title">仪表盘</span>
          </el-menu-item>
          <el-menu-item index="/admin/user">
            <i class="el-icon-user"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/sort">
            <i class="el-icon-folder"></i>
            <span slot="title">分类管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/topic">
            <i class="el-icon-s-operation"></i>
            <span slot="title">题目管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/grades">
            <i class="el-icon-edit"></i>
            <span slot="title">成绩查看</span>
          </el-menu-item>
          <el-menu-item index="/admin/monitor-info">
            <i class="el-icon-s-platform"></i>
            <span slot="title">答题监控</span>
          </el-menu-item>
          <el-menu-item index="/admin/cloud-config">
            <i class="el-icon-s-order"></i>
            <span slot="title">云配置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Admin",
  data() {
    return {
      isCollapse: false
    }
  },
  methods: {
    toTask() {
      this.$router.push('/task').catch((err) => err)
    },
    quit() {
      this.$axios2.post('/quit').then((res) => {
        this.$message({
          message: res.data.msg,
          type: 'success'
        });
        this.$router.replace('/')
      })
    },
  },
  mounted() {
    this.$axios2.post('/login').then((res) => {
      let code = res.data.code
      if (code === 200) {
        this.$axios2.post('/auth').then((res) => {
          let code = res.data.code
          if (code === 1) {
            this.$router.push('/task')
          }
        })
      } else {
        this.$router.push('/')
      }
    })
  }
}
</script>

<style scoped>
.admin-menu {
  height: calc(100vh - 60px);
  width: 200px;
}

</style>